package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("userShopController")
@RequestMapping("/user/shop")
@Api(tags = "店铺相关接口")
//这里名称和admin中的名称一样，所以需要指定bean的名称
public class ShopController{

    @Autowired
    private RedisTemplate redisTemplate;

    private static final String key = "SHOP_STATUS";

    //获取状态
    @GetMapping("/status")
    @ApiOperation( "获取营业状态")
    public Result<Integer> getStatus(){
        //可以直接强转为integer，因为放进去的时候是integer，取出来可以强转
        Integer shopStatus =(Integer) redisTemplate.opsForValue().get(key);
        log.info("获取店铺营业状态: {}" ,shopStatus == 1 ? "营业中" : "打烊中");
        return Result.success(shopStatus);
    }



}
